#include <pic.h>
#include <OSA.h>

unsigned char counter;

OST_QMSG    qmsg;

OST_MSG buf[5];

//------------------------------------------------------------------------------
void Task_T1 (void)
{
    OST_MSG     msg;
    for (;;)
    {
        counter++;
        OS_Yield();
        counter++;
        OS_SendQMsg(qmsg, msg);
    }
}


//------------------------------------------------------------------------------
void Task_T2 (void)
{
    OST_MSG     msg;
    for (;;)
    {
        counter++;
        OS_Yield();
        counter++;
        OS_WaitQMsg(qmsg, msg);
    }
}


//------------------------------------------------------------------------------
void Task_T3 (void)
{
    OST_MSG     msg;
    for (;;)
    {
        counter++;
        OS_Yield();
        counter++;
        OS_WaitQMsgTimeout(qmsg, msg, 100);
    }
}


//------------------------------------------------------------------------------
void main (void)
{
    OS_Init();
    OS_CreateTask(1, Task_T1);
    OS_CreateTask(1, Task_T2);
    OS_CreateTask(1, Task_T3);

    OS_CreateQMsg(qmsg, buf, 5);

    for (;;)
    {
        asm(" CLRWDT ");
        OS_Timer();
        OS_Sched();
    }
}
